package com.liu.efk.controller;

import com.liu.efk.domain.Drole;
import com.liu.efk.domain.DuserInfo;
import com.liu.efk.domain.ResultVo;
import com.liu.efk.dto.CodeProjectDto;
import com.liu.efk.service.RedisService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by shi860715@126.com
 * Date 2021/3/5 10:30
 * Description
 */
@RestController
@RequestMapping("/redis")
@Slf4j
@CrossOrigin
public class ProjectController {

    @Autowired
     RedisService redisService;

    @Autowired
    RedisTemplate redisTemplate;

    @GetMapping("/projects")
    public ResultVo getProject(){
       List<CodeProjectDto> list = redisService.setRedisCodeProject();

       return  ResultVo.success(list);
    }


    @GetMapping("roles")
    public ResultVo getRoles(){
        List<Drole> list = redisService.setRedisROles();
        return ResultVo.success(list);
    }


    @GetMapping("userInfos")
    public ResultVo getUserInfo(){
        List<DuserInfo> list = redisService.setRedisUserInfo();

        list.forEach(e->{
            String username1 = (String) redisTemplate.opsForValue().get("users_"+e.getMobilephone());
            log.info(username1);
        });


        return ResultVo.success(list);
    }


}
